// pages/mineModule/diet/diet.js
var util = require('../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    todayTime:"",
    formData: {},
    rules: [{
      name: 'breakfastCalories',
      rules: {required: true, message: '早餐卡路里是必填项'}
    },{
      name: 'lunchCalories',
      rules: {required: true, message: '午餐卡路里是必填项'}
    },{
      name: 'dinnerCalories',
      rules: {required: true, message: '晚餐卡路里是必填项'}
    },{
      name: 'totalHeat',
      rules: {required: false, message: ''}
    }
  ]
  },
  formInputChange(e) {
    const {field} = e.currentTarget.dataset
    this.setData({
        [`formData.${field}`]: e.detail.value
    })
  },
  submitForm () {
    let that=this
    let total = 0;
    total=Number(that.data.formData.breakfastCalories)+Number(that.data.formData.lunchCalories)+Number(that.data.formData.dinnerCalories)
    that.setData({
      [`formData.totalHeat`] : total
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var dayTime = util.formatTime(new Date());
    var dayTimes=dayTime.split(" ")[0].split("/")
    // console.log(dayTimes)
    var today=dayTimes[0]+"年"+dayTimes[1]+"月"+dayTimes[2]+"日"
    this.setData({
      todayTime:today
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})